{% extends "forum/base.html" %}
{% load static %}

{% block search %}

{% if messages %}
  {% for msg in messages %}
    <script>
      alert('{{ msg.message }}');
    </script>
  {% endfor %}
{% endif %}

<!-- 搜索栏 -->
<div class="hero-unit blow">
  <h1>模拟交易大厅</h1>
  <!-- 左边网站图片展示框 -->
  <div class="home-img">
    <img src="{% static 'img/template_logo.png' %}">
  </div>
  <!-- 右侧二维码展示？放图片也行 -->
  <div class="qr-code">
    关
    <br />
    注
    <br />
    我
    <br />
    们
    
    <img src="{% static 'img/qr-code1.jpg' %}" /> 
    <img src="{% static 'img/qr-code2.jpg' %}" />
    <img src="{% static 'img/qr-code3.jpg' %}" />
    <img src="{% static 'img/qr-code4.jpg' %}" />
  </div>
  <!-- /右侧二维码展示？ -->
  <!-- 主搜索栏 -->
  <div class="main-search">        
        <form action="{% url 'forum:index' %}" method="POST" name="search">
          {% csrf_token %}
          <input  id="search-box" type="search" placeholder="请输入..." name="search_item" required/>&nbsp
          <!-- 加事件监听 -->
          <button type="submit" name="search_plate"><i>进板块</i></button>
          <button type="submit" name="search_post"><i>查文章</i></button>
          <button type="submit" name="search_stock"><i>搜股票</i></button>
        </form>
        
  </div>
  <!-- /主搜索栏 -->
  <div class="hot-search">
    <img src="{% static 'img/icon-hot.png' %}" /> 
    <span style="font-weight:bold;">热门搜索：</span>
    <!-- 为了好看 可以给他固定下来（字数比较重要 会影响排版） -->
    <a href="{% url 'forum:stock_info' '南大光电' %}">南大光电</a>&nbsp&nbsp
    <a href="{% url 'forum:stock_info' '浙大网新' %}">浙大网新</a>&nbsp&nbsp
    <a href="{% url 'forum:stock_info' '北大医药' %}">北大医药</a>&nbsp&nbsp
    <a href="{% url 'forum:stock_info' '科大讯飞' %}">科大讯飞</a>
  </div>
  
</div>
<!-- /搜索栏 -->
{% endblock search %}

{% block more %}

<div class="content">

    <!-- Page header -->
    <div class="page-header">
                
      <h1>账户信息</h1>
  
    </div>
    <!-- /Page header -->
  
    <!-- Page container -->
    <div class="page-container">
        <div>
            <h3>用户名：{{ user_name }}</h3>
        </div>
    
        <div>
            <h3>现金：{{ user_cash }}</h3>
        </div>
    
        <div>
            <h3>总资产：{{ user_capital }}</h3>
        </div>
    
        <div>
            <h3>委托列表</h3>
            <article>
              <table class="datatable table table-striped table-bordered" id="example1">
                <thead>
                  <tr>
                    <th>日期</th>
                    <th>时间</th>
                    <th>代码</th>
                    <th>名称</th>
                    <th>操作</th>
                    <th>备注</th>
                    <th>数量</th>
                    <th>价格</th>
                    <th>撤销</th>
                  </tr>
                </thead>

                <tbody>
                  {% for commission in commission_list %}
                  <tr class="odd gradeX">
                    <td>{{ commission.date }}</td>
                    <td>{{ commission.time1 }}</td>
                    <td>{{ commission.code }}</td>
                    <td>{{ commission.name }}</td>
                    <td>{{ commission.operation }}</td>
                    <td>{{ commission.note }}</td>
                    <td>{{ commission.amount }}</td>
                    <td>{{ commission.price }}</td>
                    {% if commission.note == "未成交" %}
                    <td style="text-align: center;"><a href="{% url 'mockexchange:cancel' commission.index %}"><button type="submit" >撤销委托</button></a></td>
                    {% else %}
                    <td></td>
                    {% endif %}
                  </tr>
                  {% empty %}
                  没有委托记录
                  {% endfor %}
                </tbody>

              </table>
            </article>
        </div>
    
        <div>
            <h3>成交列表</h3>
            <article>
              <table class="datatable table table-striped table-bordered" id="example2">
                <thead>
                  <tr>
                    <th>日期</th>
                    <th>时间</th>
                    <th>代码</th>
                    <th>名称</th>
                    <th>操作</th>
                    <th>数量</th>
                    <th>价格</th>
                  </tr>
                </thead>

                <tbody>
                  {% for deal in deal_list %}
                  <tr class="odd gradeX">
                    <td>{{ deal.date }}</td>
                    <td>{{ deal.time1 }}</td>
                    <td>{{ deal.code }}</td>
                    <td>{{ deal.name }}</td>
                    <td>{{ deal.operation }}</td>
                    <td>{{ deal.amount }}</td>
                    <td>{{ deal.price }}</td>
                  </tr>
                  {% empty %}
                  没有成交记录
                  {% endfor %}
                </tbody>

              </table>
            </article>
        </div>
    
        <div>
            <h3>持仓列表</h3>
            <article>
              <table class="datatable table table-striped table-bordered" id="example3">
                <thead>
                  <tr>
                    <th>代码</th>
                    <th>名称</th>
                    <th>总余额</th>
                    <th>可用余额</th>
                    <th>冻结余额</th>
                    <th>成本</th>
                    <th>价格</th>
                  </tr>
                </thead>

                <tbody>
                  {% for stock in ownedstock_list %}
                  <tr class="odd gradeX">
                    <td>{{ stock.code }}</td>
                    <td>{{ stock.name }}</td>
                    <td>{{ stock.whole_balance }}</td>
                    <td>{{ stock.available_balance }}</td>
                    <td>{{ stock.blocked_balance }}</td>
                    <td>{{ stock.cost }}</td>
                    <td>{{ stock.price }}</td>
                  </tr>
                  {% empty %}
                  没有持仓股票
                  {% endfor %}
                </tbody>

              </table>
            </article>

        </div>
    </div>
    <!-- /Page container -->
</div>

<div class="hero-unit blow">
    <div class="nav-secondary inverse">
        <nav>
          <ul>
            <li><a class="wuxify-me" href="/mockexchange/userinfo/"><span class="icon-user"></span>账户信息</a></li>
            <li><a class="wuxify-me" href="/mockexchange/buy/"><span class="icon-shopping-cart"></span>买入</a></li>
            <li><a class="wuxify-me" href="/mockexchange/sell/"><span class="icon-upload-alt"></span>卖出</a></li>
            <li><a class="wuxify-me" href="/mockexchange/capital_rank/"><span class="icon-sort"></span>排行榜</a></li>
          </ul>
        </nav>
      </div>
</div>

<div class="content">

    <!-- Page header -->
    <div class="page-header">
                
      <h1>交易规则</h1>
  
    </div>
    <!-- /Page header -->
  
    <!-- Page container -->
    <div class="page-container">
        <ul>
            <li><h3>每个用户初始资产200000，初始现金200000，资产=现金+持有股票的市值</h3></li>
            <li><h3>提交买入委托时，当且仅当委托的价格*数量小于等于现金时才能提交。提交成功后，资产和现金减去价格*数量。若撤销该委托，资产和现金复原。买入委托成交后，会添加的持有股票，该部分余额为冻结余额，第二天解冻，资产会加上这部分的市值</h3></li>
            <li><h3>提交卖出委托时，当且仅当持有该股票的数量大于等于委托的数量才能提交。提交成功后，持有的该股票可用余额和冻结余额分别减去和加上委托的数量。若撤销该委托，余额复原。卖出委托成交后，冻结余额会减去该部分数量，资产和现金会相应增加</h3></li>
            <li><h3>交易时间：每周一到周五上午时段9:30-11:30，下午时段13:00-15:00。周六、周日以及公告的休市日不交易。</h3></li>
        </ul>
    </div>
    <!-- /Page container -->
</div>
{% endblock more %}